package com.poisonh.unifiedauth.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.poisonh.unifiedauth.R;
import com.poisonh.unifiedauth.utils.ConstantUitls;
import com.poisonh.unifiedauth.utils.PreferencesUtils;
import com.poisonh.unifiedauth.widget.CircleImageView;
import com.zhy.autolayout.AutoLinearLayout;

/**
 * 身份信息
 * Created by PoisonH on 2016/6/28.
 */
public class SettingPerfectActivity extends BaseActivity implements View.OnClickListener
{
    private TextView mTvReallyName;
    private TextView mTvCard;
    private CircleImageView mCiHead;
    private TextView mTvPerfect;
    private String mStrReallyName;
    private String mStrCard;
    private String mStrHeadUrl;

    private TextView mTvState;
    private TextView mTvVideoStateTips;

    private AutoLinearLayout mAllLayout;

    @Override
    protected void loadContentView(Bundle savedInstanceState)
    {
        setContentView(R.layout.activity_settingperfect);
        mStrReallyName = getIntent().getStringExtra("REALLYNAME");
        mStrCard = getIntent().getStringExtra("CARD");
        mStrHeadUrl = getIntent().getStringExtra("HEADURL");
        initTitleView();
        initView();
    }

    @Override
    protected void initView()
    {
        mRightBtn.setVisibility(View.GONE);
        mLeftBtn.setOnClickListener(this);
        setTitleTxt("身份信息");
        mTvState = (TextView) findViewById(R.id.tv_userinfo_check);
        mTvPerfect = (TextView) findViewById(R.id.tv_perfect);
        mCiHead = (CircleImageView) findViewById(R.id.civ_userinfo_head);
        mTvReallyName = (TextView) findViewById(R.id.tv_userinfo_reallyname);
        mTvCard = (TextView) findViewById(R.id.tv_userinfo_card);
        mTvVideoStateTips = (TextView) findViewById(R.id.txt_videostate_tips);
        mAllLayout = (AutoLinearLayout) findViewById(R.id.all_layout);
        mTvPerfect.setOnClickListener(this);
        AccordingToStateSetValue();
        if (!mStrCard.equals("null"))
        {
            mTvCard.setText(mStrCard);
        }
        if (!mStrReallyName.equals("null"))
        {
            mTvReallyName.setText(mStrReallyName);
        } else
        {
            mTvState.setText("未实名");
            mTvState.setBackgroundColor(getResources().getColor(R.color.greyish));
        }
        if (!mStrHeadUrl.equals("null"))
        {
            Glide.with(getApplication()).load(mStrHeadUrl).into(mCiHead);
        }
    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.ib_left_btn:
                finish();
                break;
            case R.id.tv_perfect:
//                if (!PreferencesUtils.getBoolean(this, "VideoState"))
//                {
//                    jumpActivity(this, FFmpegRecordActivity.class);
//                }
                //ConstantUitls.mStrVideoState != null && (ConstantUitls.mStrVideoState.equals("2") || ConstantUitls.mStrVideoState.equals("3")) ||

                if (PreferencesUtils.getString(this, "VIDEOSTATE").equals("2") || PreferencesUtils.getString(this, "VIDEOSTATE").equals("3"))
                {
                    jumpActivity(this, FFmpegRecordActivity.class);
                }
                break;
        }
    }

    /**
     * 根据状态设置是否显示完善信息
     */
    private void AccordingToStateSetValue()
    {
        //如果没有进行实名认证，或者视频未通过则显示完善信息
//        if (!PreferencesUtils.getBoolean(this, "VideoState") &&
//                !ConstantUitls.mStrVideoState.equals("0") &&
//                !ConstantUitls.mStrVideoState.equals("1"))
//        {
//            mAllLayout.setVisibility(View.VISIBLE);
//        } else
//        {
//            mAllLayout.setVisibility(View.GONE);
//        }
        String state = PreferencesUtils.getString(this, "VIDEOSTATE");
        //0待审核
        //未上传
        if (state.equals("3") || state == null)
        {
            mTvVideoStateTips.setText("视频未上传");
        } else if (state.equals("0"))
        {
            mTvVideoStateTips.setText("视频审核中...");
            mTvPerfect.setVisibility(View.GONE);
        }
        //审核通过
        else if (state.equals("1"))
        {
            mAllLayout.setVisibility(View.GONE);
        }
        //审核不通过
        else if (state.equals("2"))
        {
            mTvVideoStateTips.setText("视频审核未通过");
        }
    }
}
